package cn.t.enums.user;


import cn.t.core.enums.base.CommonEnum;
import cn.t.core.exception.BizException;
import cn.t.core.enums.base.CommonError;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author l
 */

@Getter
@AllArgsConstructor
public enum RoleTypeEnum implements CommonEnum<Integer, String> {

    ANONYMOUS(10, "个人匿名角色"), SYSTEM(11, "运营管理角色"), MATERIAL_ANONYMOUS(20, "个人匿名领料角色"), MATERIAL_ISSUE(21, "领料角色"), STOCK_REPLENISH(31, "补货角色");

    @JsonValue
    @EnumValue
    private final Integer code;
    private final String name;

    public static RoleTypeEnum getByCode(Integer source) {
        for (RoleTypeEnum value : RoleTypeEnum.values()) {
            if (value.code.equals(source)) {
                return value;
            }
        }

        throw new BizException(CommonError.ILLEGAL_PARAMETER);
    }
}